﻿using System;
using Autofac;
using Autofac.Integration.WebApi;
using Inovout.Component;

namespace Inovout.Web.Http
{
    public class WebApiComponentResolver : IComponentResolver
    {
        private AutofacWebApiDependencyResolver autofacWebApiDependencyResolver;
        public WebApiComponentResolver(AutofacWebApiDependencyResolver autofacWebApiDependencyResolver)
        {
            this.autofacWebApiDependencyResolver = autofacWebApiDependencyResolver;
        }
        protected ILifetimeScope Container
        {
            get
            {
                return autofacWebApiDependencyResolver.GetRootLifetimeScope();
            }
        }
        public bool IsRegistered<TService>()
        {
            return Container.IsRegistered<TService>();
        }
        public object Resolve(Type serviceType)
        {
            return Container.Resolve(serviceType);
        }
        public TService Resolve<TService>(Type serviceType)
        {
            return (TService)Resolve(serviceType);
        }

        public TService Resolve<TService>()
        {
            return Container.Resolve<TService>();
        }

        public bool IsRegistered(Type serviceType)
        {
            return Container.IsRegistered(serviceType);
        }

        public IComponentResolver BeginLifetimeScope()
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }
}
